import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);
import molle from './molle.js';
import userInfo from './userInfo.js';
import conditional from './conditional.js';
import tableData from './tableData.js';

export default new Vuex.Store({
  modules: {
    molle,
    userInfo,
    conditional,
    tableData,
  },
  state: {
    TOKEN: null,
    msg: { name: 'a123' },

    dialog: {
      数据统计: { temp: [], visible: false },
      资源改派: { temp: [], visible: false },
      //表格功能从左到右
      编辑备注: { temp: null, visible: false },
      编辑标签: { temp: null, visible: false },
      拨号管理: { temp: null, step: '', visible: false },
      //最后一列的操作‘成交登记’用drawer
      录音列表: { temp: null, visible: false },
    },
    drawer: {
      成交登记: { temp: null, visible: false },

    }
  },
  getters: {
    getValue: (state) => (key) => { return state[key] },
    getTOKEN: (state) => {
      if (state.TOKEN === null) {
        state.TOKEN = localStorage.getItem('TOKEN') || null;
      }
      return state.TOKEN
    },
  },
  mutations: {
    //this.$store.commit('setValue',{key:'msg',value:'a'})
    setValue: (state, obj) => { state[obj.key] = obj.value },
    setLocal: (state, value) => {
      state.key = value;
      localStorage.setItem('key', value);
    },
    openDialogPhoneManagement: (state, { step, tempData }) => {
      state.dialog.拨号管理.visible = true;
      Vue.set(state.dialog.拨号管理, 'step', step)
      Vue.set(state.dialog.拨号管理, 'temp', tempData)
    },
    closeDialogPhoneManagement: (state) => {
      state.dialog.拨号管理.visible = false;
      Vue.set(state.dialog.拨号管理, 'step', '')
      Vue.set(state.dialog.拨号管理, 'temp', null)
    },
    otherStep: (state, { step }) => {
      Vue.set(state.dialog.拨号管理, 'step', step)
    },
    toggleDialog: (state, { type, key, tempData }) => {
      state[type][key].visible = !state[type][key].visible;
      Vue.set(state[type][key], 'temp', tempData)
    },
    setCustomerChangeList: (state, rowMapId) => {
      let tar = state.dialog.资源改派.temp;
      tar.splice(0, tar.length)
      rowMapId.forEach((v) => { tar.push(v) })
    },
    toggleCustomerChangeList: (state) => {
      state.dialog.资源改派.visible = !state.dialog.资源改派.visible;
    },

  },
  actions: {},
})